package solutions.leetcode.easy;

/**
 * @author lizhidong
 * <a href="https://leetcode-cn.com/problems/binary-search/">704. 二分查找</a>
 */
public class Solution704 {

    public int search(int[] nums, int target) {
        return search(nums, target, 0, nums.length);
    }

    private int search(int[] nums, int target, int left, int right) {
        if (left > right) {
            return -1;
        }
        int mid = (left + right) / 2;
        if (nums[mid] == target) {
            return mid;
        } else if (nums[mid] < target) {
            return search(nums, target, mid + 1, right);
        } else {
            return search(nums, target, left, mid - 1);
        }
    }

    public static void main(String[] args) {
        Solution704 solution = new Solution704();
    }
}